import request, { IResposeItem } from "@/configs/request"

/**
 * 获取枚举类
 * @param type 
 * @returns 
 */

export interface ITypeEnum {
  value: number,
  str: string
}

export const enumTypeList = {
  consultAnnex: "consultAnnex",// 会诊病史附件标签
  cancelReason: "cancelReason",// 取消/拒绝会诊原因
  consultGroupStatus: "consultGroupStatus",// 	会诊小组状态
  consultStatus: "consultStatus",// 	会诊状态
  absentReason: "absentReason",// 		会诊缺席原因
  attendStatus: "attendStatus",// 	用户对会诊的参与状态
  dataStatus: "dataStatus",// 	停用/启用枚举类
  deptType: "deptType",// 	科室类型
  userStatus: "userStatus",// 		医生状态
  loginChannel: "loginChannel",// 		登入渠道
  menuType: "menuType",// 		菜单类型
  patientType: "patientType",// 	患者类型
  roleType: "roleType",// 		用户角色类型
  sex: "sex",// 		性别
}

// interface IEnumParms {
//   type: string,// 枚举类型
//   includeDefault?: boolean | false,// 是否加上全部
// }

// 防空声明
export type IResposeWithNull<R> = {
  [K in keyof R]?: R[K] | null | undefined
}

export const getEnum = async (type: string, includeDefault = false): Promise<IResposeItem<Array<ITypeEnum>>> => {
  return request.get(`/common/enum/get?type=${type}&includeDefault=${includeDefault}`)
}

export interface IuploadFile<T = any> {
  file: T
}

// 文件信息
export interface IfileRespose {
  id: string;
  fileName: string;
  fileUrl: string;
  size: number;
  sizeStr: string;
  suffix: string;
  remark?: string;
}

/**
 * 上传文件
 * @param parmas 
 * @returns 
 */
export const uploadFile = async (file: any): Promise<IResposeItem<IfileRespose>> => {
  return request.post("/sys/file/upload", file, { headers: { "Content-Type": "multipart/form-data" }, onUploadProgress: () => { } })
}

/**
 * 获取单个文件详情
 * @param deptId 
 * @returns 
 */
export const getFileInfo = async (deptId: number): Promise<IResposeItem<IfileRespose>> => {
  return request.get(`/common/enum/get?type=${deptId}`)
}